package cn.wanho.service.impl;

import cn.wanho.CmsUserThreadLocal.UserThreadLocal;
import cn.wanho.dao.CmsClassMapper;
import cn.wanho.dao.CmsUserMapper;
import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.rvo.StudentVO;
import cn.wanho.rvo.selectTeacherStageVO;
import cn.wanho.service.CmsStudentService;
import cn.wanho.util.QiniuUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CmsStudentServiceImpl implements CmsStudentService {
    @Resource
    private CmsUserMapper cmsUserMapper;

    private static final String URL = "http://rgb4gi8ky.hn-bkt.clouddn.com/";

    /**
     * 修改学生个人信息
     * @param bytes
     * @param introduction
     * @param studentId
     * @return
     */
    @Override
    public ResultVO modifyStudentSelf(byte[] bytes, String introduction, Integer studentId) {
        String path = QiniuUtil.upload(bytes);
        int i=0;
        i = cmsUserMapper.modifyStudentSelf(path, introduction, studentId);
        if (i>0){
            return ResultVO.success(ResultEnum.UPDATE_STUDENT_INFORMATION_SUCCESS.getResCode(), ResultEnum.UPDATE_STUDENT_INFORMATION_SUCCESS.getResMsg());
        }else {
            return ResultVO.failure(ResultEnum.UPDATE_STUDENT_INFORMATION_FAILURE.getResCode(), ResultEnum.UPDATE_STUDENT_INFORMATION_FAILURE.getResMsg());
        }
    }

    /**
     * 查询学生个人信息
     * @return
     */
    @Override
    public ResultVO selectMyself() {
        Integer studentId= UserThreadLocal.get().getId();
        StudentVO student = cmsUserMapper.selectMyself(studentId);
        if (student == null){
            return ResultVO.success(ResultEnum.STUDENT_INFORMATION_FAILURE.getResCode(), ResultEnum.STUDENT_INFORMATION_FAILURE.getResMsg());
        }else {
            return ResultVO.success(ResultEnum.STUDENT_INFORMATION_SUCCESS.getResCode(), ResultEnum.STUDENT_INFORMATION_SUCCESS.getResMsg(),student);
        }
    }

    /**
     * 查询学生当前阶段和老师
     * @return
     */
    @Override
    public ResultVO showInfo() {
        Integer studentId=UserThreadLocal.get().getId();
        selectTeacherStageVO selectTeacherStageVO = cmsUserMapper.showinfo(studentId);
        if (selectTeacherStageVO==null){
            return ResultVO.failure(ResultEnum.STUDENT_STAGE_TEACHER_FAILURE.getResCode(), ResultEnum.STUDENT_STAGE_TEACHER_FAILURE.getResMsg());
        }else {
            return ResultVO.success(ResultEnum.STUDENT_STAGE_TEACHER_SUCCESS.getResCode(), ResultEnum.STUDENT_STAGE_TEACHER_SUCCESS.getResMsg(),selectTeacherStageVO);
        }


    }
}
